# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=cython
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-cython")
pkgver=0.29.26
pkgrel=1
pkgdesc="C-Extensions for Python (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://cython.org/"
license=('APACHE')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/cython/cython/archive/${pkgver}.tar.gz")
sha256sums=('bb72b2f0ef029472759c711f0a4bded6e15e3f9bda3797550cef3c1d87d02283')

prepare() {
  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM}| true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
  sed -e "s|\/usr\/bin\/python|${MINGW_PREFIX}\/bin\/python|" -i python-build-${MSYSTEM}/setup.py
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  DISTUTILS_DEBUG=1 \
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  DISTUTILS_DEBUG=1 \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
                              --root="${pkgdir}" --optimize=1 --skip-build

  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done
}
